package com.lqq.school.controller;


import com.lqq.school.domain.Dormitory;
import com.lqq.school.domain.Student;
import com.lqq.school.mapper.DormitoryMapper;
import com.lqq.school.mapper.StudentMapper;
import com.sun.org.apache.xpath.internal.operations.Mod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lqq
 * @since 2021-06-11
 */
@Controller
@RequestMapping("/dormitory")
public class DormitoryController {
    //dormitory
    @Autowired
    private DormitoryMapper dormitoryMapper;
    @GetMapping("/dor")
    public String dormitory(Model model) {
        List<Dormitory> dormitories = dormitoryMapper.selectList(null);
        model.addAttribute("list", dormitories);
        return "/admin/dorlist";
    }

    @GetMapping("/toDorUpdate/{dormitoryId}")
    public String toDorUpdate(@PathVariable("dormitoryId") String dormitoryId, Model model) {
        System.out.println("获取宿舍信息");
        Dormitory dormitory = dormitoryMapper.selectById(dormitoryId);
        //System.out.println(dormitory);
        model.addAttribute("dor", dormitory);
        return "/admin/dorupdate";
    }

    @PostMapping("/dorUpdate")
    public String dorUpdate(Dormitory dormitory) {
        //System.out.println(dormitory);
        dormitoryMapper.updateById(dormitory);
        return "redirect:/dormitory/dor";
    }
}

